package incidencies.android.es;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

import org.apache.http.HttpException;
import org.apache.http.client.ClientProtocolException;

import android.content.Context;
import android.os.AsyncTask;

public class IncidenciesUpdate extends AsyncTask<Context, Integer, Context> {
	@Override
	protected Context doInBackground(Context... contexts) {
		HttpUtil utils=new HttpUtil();
		try {
			List<Spore> spores=utils.getAll(Spore.class, "");
			List<Location> locations=utils.getAll(Location.class, "");
			List<Mesure> mesures=utils.getAll(Mesure.class, "");
			
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (HttpException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
			
		
		return null;
	}

	public String convertStreamToString(InputStream is) throws IOException {
		/*
		 * To convert the InputStream to String we use the
		 * BufferedReader.readLine() method. We iterate until the BufferedReader
		 * return null which means there's no more data to read. Each line will
		 * appended to a StringBuilder and returned as String.
		 */
		if (is != null) {
			StringBuilder sb = new StringBuilder();
			String line;

			try {
				BufferedReader reader = new BufferedReader(
						new InputStreamReader(is, "UTF-8"));
				while ((line = reader.readLine()) != null) {
					sb.append(line).append("\n");
				}
			} finally {
				is.close();
			}
			return sb.toString();
		} else {
			return "";
		}
	}
}
